import express from "express";
import usersRoutes from "./routes/users.routes.js";
import requestLoggerMiddleware from './middleware/logger.middleware.js';
import swaggerMiddleware from './middleware/swagger.middleware.js';
import responseMiddleware from './middleware/response.middleware.js';
import { PORT } from "./config/config.js";

const app = express();


app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// 使用统一响应格式中间件
app.use(responseMiddleware);
// app.use(morgan("dev"));

// 使用日志中间件
app.use(requestLoggerMiddleware);

// middlewares
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

app.use(usersRoutes);

// 集成 Swagger 文档
swaggerMiddleware(app);


// 捕获未匹配路由并重定向到指定页面
app.use((req, res) => {
    res.redirect("/api-docs");
});

app.listen(PORT);
// eslint-disable-next-line no-console
console.log("Server on port", PORT);
